package com.ruoyi.pingjiao.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.pingjiao.domain.Student;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pingjiao.domain.Metaclass;
import com.ruoyi.pingjiao.service.IMetaclassService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 行政班级管理Controller
 * 
 * @author 胡浩鹏
 * @date 2022-10-15
 */
@RestController
@RequestMapping("/score/metaclass")
public class MetaclassController extends BaseController
{
    @Autowired
    private IMetaclassService metaclassService;

    /**
     * 查询行政班级管理列表
     */
    @PreAuthorize("@ss.hasPermi('score:metaclass:list')")
    @GetMapping("/list")
    public TableDataInfo list(Metaclass metaclass)
    {
        startPage();
        List<Metaclass> list = metaclassService.selectMetaclassList(metaclass);
        return getDataTable(list);
    }

    /**
     * 查询行政班级管理列表不带分页
     */
    @PreAuthorize("@ss.hasPermi('score:metaclass:list')")
    @GetMapping("/listSimple")
    public TableDataInfo listSimple(Metaclass metaclass)
    {
        List<Metaclass> list = metaclassService.selectMetaclassList(metaclass);
        return getDataTable(list);
    }

    @ApiOperation("批量导入行政班级信息，通过Excel文件")
    @PreAuthorize("@ss.hasAnyRoles('collegeAdmin,admin,systemAdmin')")
    @Log(title = "行政班级管理", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception {
        ExcelUtil<Metaclass> util = new ExcelUtil<Metaclass>(Metaclass.class);
        List<Metaclass> metaclasses = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = metaclassService.importStudent(metaclasses, operName);
        return success(message);
    }

    /**
     * 导出行政班级管理列表
     */
    @PreAuthorize("@ss.hasPermi('score:metaclass:export')")
    @Log(title = "行政班级管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Metaclass metaclass)
    {
        List<Metaclass> list = metaclassService.selectMetaclassList(metaclass);
        ExcelUtil<Metaclass> util = new ExcelUtil<Metaclass>(Metaclass.class);
        util.exportExcel(response, list, "行政班级管理数据");
    }
    @PreAuthorize("@ss.hasPermi('score:metaclass:export')")
    @Log(title = "行政班级列表模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export1")
    public void export1(HttpServletResponse response, Metaclass metaclass)
    {
//        List<Metaclass> list = metaclassService.selectMetaclassList(metaclass);
        ExcelUtil<Metaclass> util = new ExcelUtil<Metaclass>(Metaclass.class);
        util.exportExcel(response, null, "行政班级管理数据");
    }
    /**
     * 获取行政班级管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('score:metaclass:query')")
    @GetMapping(value = "/{meataclassId}")
    public AjaxResult getInfo(@PathVariable("meataclassId") Long meataclassId)
    {
        return AjaxResult.success(metaclassService.selectMetaclassByMeataclassId(meataclassId));
    }

    @PreAuthorize("@ss.hasPermi('score:metaclass:query')")
    @GetMapping("listStudent/{metaclassId}")
    public AjaxResult getStudentListByMeataclassId(@PathVariable("metaclassId") Long meataclassId)
    {
        return AjaxResult.success(metaclassService.selectStudentByMeataclassId(meataclassId));
    }

    /**
     * 新增行政班级管理
     */
    @PreAuthorize("@ss.hasPermi('score:metaclass:add')")
    @Log(title = "行政班级管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Metaclass metaclass)
    {
        return toAjax(metaclassService.insertMetaclass(metaclass));
    }

    /**
     * 修改行政班级管理
     */
    @PreAuthorize("@ss.hasPermi('score:metaclass:edit')")
    @Log(title = "行政班级管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Metaclass metaclass)
    {
        return toAjax(metaclassService.updateMetaclass(metaclass));
    }

    /**
     * 删除行政班级管理
     */
    @PreAuthorize("@ss.hasPermi('score:metaclass:remove')")
    @Log(title = "行政班级管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{meataclassIds}")
    public AjaxResult remove(@PathVariable Long[] meataclassIds)
    {
        return toAjax(metaclassService.deleteMetaclassByMeataclassIds(meataclassIds));
    }
}
